package test.expand;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 扩展spring上下文
 */

public class ClassPathXmlContext extends ClassPathXmlApplicationContext {

    private String[] configLocations;

    public ClassPathXmlContext(String... configLocations) {
        this.configLocations = configLocations;
    }

    /**
     * 初始化资源属性方法的扩展
     */
    @Override
    protected void initPropertySources() {
        //设置一个必须的属性值，spring启动时，如果环境对象中没有key为baizhigang的属性，将报错
        getEnvironment().setRequiredProperties("baizhigang");
    }

    /**
     * 设置beanfactory中
     */
    @Override
    protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory) {
        beanFactory.setAllowBeanDefinitionOverriding(true);
        beanFactory.setAllowCircularReferences(true);
    }
}
